# -*-coding: utf-8 -*-
import base64
import os
import sys


def pic2base64():
    arg_list = sys.argv
    arg_number = len(sys.argv)
    if arg_number > 1:
        file = arg_list[1]
    else:
        print('未找到文件')
        # os.system("pause")
        return 0
    f = open(file, 'rb')
    ls_f = base64.b64encode(f.read())
    f.close()
    if arg_number == 3:
        label = arg_list[2]
    else:
        label = 'basestr'
    ret = '[' + label + ']: data:image/jpeg;base64,'+ls_f.__str__()[2:-1]
    fo = open('base64str.txt', 'w')
    fo.write(ret)
    fo.close()
    print('已生成', file, "对应的base64编码")


if __name__ == '__main__':
    pic2base64()
